<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>字符串练习</title>
	</head>
	<body>
		字符串: <input type="text" id="str">
		子串: <input type="text" id="subStr">
		<input type="button" value="确定" id="btn">
	</body>
</html>
<script>
	// 把一个字符串中的
	// 获取元素
	var strInput = document.getElementById('str');
	var subStrInput = document.getElementById('subStr');
	var btn = document.getElementById('btn');

	// 添加点击事件
	btn.onclick = function() {
		// 获取输入框中的值
		var str = strInput.value;
		var subStr = subStrInput.value;

		var r = up(str, subStr);
		strInput.value = r;
	};

	var str = "babbbbabb";
	var s = "a";
	// 抄20遍
	function up(str1, str2) {
		
		var n = str1.indexOf(str2);
		if (n == -1) {
			return str1;
		}
		var r = "";
		var strL = str1.slice(0, n);
		var strR = str1.slice(n + str2.length);

		r += strL + str2.toUpperCase() + up(strR, str2);
		return r;

	}
	var r = up(str, s);
	console.log(r);

	/*	
		str1 = "babbbbabb";
		str2 = "a";
		var n = str1.indexOf(str2);  n = 1;
		var r = "";
		var strL = str1.slice(0, 1);  strL = "b";
		var strR = str1.slice(2); strR = "bbbbabb";
		r += "b" + "A" + up("bbbbabb", "a");  
			str1 = "bbbbabb", str2 = "a";
			var n = str1.indexOf(str2);  n = 4;
			var r = "";
			var strL = str1.slice(0, 4);  strL = "bbbb";
			var strR = "bb";
			r += "bbbb" + "A" + "bb";
				str1 = "bb", str2 = "a";
				var n = str1.indexOf(str2);  n = -1;
				return "bb";
			return "bbbbAbb";
		r = "bAbbbbAbb";
		return r;
				

	*/





</script>